package com.module.overview.ui.summaryReport

import android.view.View
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import com.alibaba.android.arouter.facade.annotation.Route
import com.common.app.base.AppActivity
import com.common.app.core.RouterHub
import com.common.app.utls.HeadTitleUtils
import com.common.base.adapter.BaseFragmentPageAdapter
import com.common.base.utils.StatusBarUtils
import com.module.overview.R
import com.module.overview.databinding.OverviewActivitySummaryReportMainBinding

/**
 * 作者：sosou
 * <p>
 * 版本：1.0
 * <p>
 * 创建日期：2025/07/22
 * <p>
 * 描述：总结报告页面
 * <p>
 * 修订历史：
 */
@Route(path = RouterHub.ROUTER_OVERVIEW_SUMMARY_REPORT_MAIN)
class SummaryReportMainActivity :
    AppActivity<OverviewActivitySummaryReportMainBinding, SummaryReportMainViewModel>(),
    View.OnClickListener {

    val TAG: String = SummaryReportMainActivity::class.java.simpleName

    override fun getViewModel() = SummaryReportMainViewModel::class.java

    override fun getViewContentBinding() = OverviewActivitySummaryReportMainBinding.inflate(layoutInflater)

    override fun isShowToolBar(): Boolean = false
    override fun isStatusBarTranslate(): Boolean = true

    override fun initViews() {
        super.initViews()
        StatusBarUtils.setStatusBarHeight(mViewContentBinding.statusView)
        StatusBarUtils.setStatusBarForegroundColor(this, true)


        val headTitleUtils = HeadTitleUtils(this)
        headTitleUtils.setTitle(getString(R.string.overview_summary_report_hint))
        headTitleUtils.setLineStyle(10)


        val titles = ArrayList<String>()
        titles.add(resources.getString(R.string.common_weekly_report_hint))
        titles.add(resources.getString(R.string.common_annual_report_hint))
        val mFragments = arrayListOf<Fragment>()
        mFragments.add(SummaryReportRecordFragment.newInstance(1))
        mFragments.add(SummaryReportRecordFragment.newInstance(2))

        val mAdapter = BaseFragmentPageAdapter(supportFragmentManager, mFragments, titles)
        mViewContentBinding.viewPager.adapter = mAdapter
        mViewContentBinding.viewPager.offscreenPageLimit = mFragments.size


        mViewContentBinding.viewPager.currentItem = 0
    }

    override fun initEvents() {
        super.initEvents()

        mViewContentBinding.viewPager.setOnPageChangeListener(MyPageChangeListener())

        mViewContentBinding.rgReport.setOnCheckedChangeListener { radioGroup, i ->
            // 选中状态改变时被触发
            when (i) {
                R.id.rbnWeeklyReport -> mViewContentBinding.viewPager.currentItem = 0
                R.id.rbnAnnualReport -> mViewContentBinding.viewPager.currentItem = 1
            }
        }

//        mViewContentBinding.v.setOnClickListener(onClick = this)
    }

    override fun lazyInitData() {
        super.lazyInitData()

    }

    override fun onDestroy() {
        super.onDestroy()
    }

    override fun onClick(v: View?) {
        when (v) {
        }
    }

    /**
     * ViewPager的监听器 当ViewPager中页面的状态发生改变时调用
     */
    inner class MyPageChangeListener : ViewPager.OnPageChangeListener {
        override fun onPageScrollStateChanged(state: Int) {}
        override fun onPageScrolled(arg0: Int, arg1: Float, arg2: Int) {}
        override fun onPageSelected(pos: Int) {
            when (pos) {
                0 -> mViewContentBinding.rbnWeeklyReport.isChecked =true
                1 -> mViewContentBinding.rbnAnnualReport.isChecked =true
            }
        }
    }
}